const path = require('path')
const HtmlPlugin = require('html-webpack-plugin')
const {CleanWebpackPlugin} = require('clean-webpack-plugin');

module.exports = {
    devServer: {
        open: false,//打包完成，自动打开浏览器
        host: '127.0.0.1',//绑定host
        port: '1024',//绑定端口
        proxy: [{
            context: ['/api'],
            target: 'http://localhost:10242',
            changeOrigin: true,//是否跨域
        }]
    },//mode用来指定构建模式，可选值有development 和 production
    devtool: 'eval-source-map',//nosources-source-map（生产），eval-source-map（开发），false
    entry: {
        index: path.join(__dirname, './src/index.js'),
        login: path.join(__dirname, './src/login.js')
    },
    mode: 'development',
    module: {
        rules: [{
            test: /\.css$/, use: ['style-loader', 'css-loader']
        }, {
            test: /\.less$/, use: ['style-loader', 'css-loader', 'less-loader']
        }, {
            test: /\.js/, use: 'babel-loader', exclude: '/node_modules/'
        }, {
            test: /\.html$/, use: 'html-loader'
        }, {
            test: /\.(png|jpe?g|gif|svg)$/i,
            use: [{
                loader: 'url-loader',
                options: {
                    limit: 8192, // 图片小于8KB时转为base64
                    fallback: { // 当文件大于limit时，使用file-loader
                        loader: 'file-loader',
                        options: {
                            outputPath: 'assets/images', // 确保大文件输出到此目录
                            name: '[contenthash].[ext]', // 保持文件名格式一致
                        }
                    }
                }
            }]
        }]
    },
    /* optimization: {
         minimize: false// 禁止提取license注释到单独的LICENSE.txt文件
     },*/
    output: {
        path: path.join(__dirname, 'dist'),
        filename: 'assets/js/[contenthash].bundle.js'
    },
    plugins: [new HtmlPlugin({
        template: './src/index.html',//指定要复制的页面
        filename: './index.html',//指定复制出来的文件名和存放路径
        favicon: './public/images/favicon.ico',
        chunks: ['index']
    }), new HtmlPlugin({
        template: './src/login.html',
        filename: './login.html',
        favicon: './public/images/favicon.ico',
        chunks: ['login']
    }), new HtmlPlugin({
        template: './src/doc.html',
        filename: './doc.html',
        favicon: './public/images/favicon.ico',
        chunks: ['doc']
    }), new CleanWebpackPlugin()],
    resolve: {
        alias: {
            '@': path.join(__dirname, 'src')
        }
    },
    performance: {
        hints: false//关闭性能提示
    }
}